const app = getApp()
Page({
	data: {
		address:{},
		cart: [],
		totalPrice: 0,
		totalNum: 0
	},
onLoad:function(opt){

},
	onShow() {
		// 获取缓存中的收货地址信息
		const address = wx.getStorageSync('address');
		// 获取缓存中购物车的数据
		let cart = wx.getStorageSync("cart") || [];
		// 过滤后的购物车数组
		cart = cart.filter(v => v.checked);
		this.setData({
			cart
		})
		this.setData({
		address
		})
		// 总价格 总数量
		let totalPrice = 0;
		let totalNum = 0;
		cart.forEach(v => {
				totalPrice += v.num * v.price;
				totalNum += v.num;		
	})
		
		this.setData({
			cart,
			totalPrice,
			totalNum,
		});
	},
	// 点击收货地址按钮
	handleChooseAddress() {
		wx.chooseAddress({
			success: (address) => {
				// 存入到缓存中
				wx.setStorageSync('address', address)
			}
		});
	},
	handleOrderPay(){
		const token = wx.get.getStorageSync("token");
		if(!token){
			wx.navigateTo({
				url: 'url',
			})

		}
	}
})